﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ProdeManagmente.DAO;
using ProdeManagmente.Model;
using DgvFilterPopup;

namespace ProdeManagmente.Forms.ABMS
{
    public partial class FrmUserResults : Form
    {
        private static FrmUserResults instance;

        private UserResultService userResultService;
        private ResultService resultService;

        private FrmUserResults()
        {
            InitializeComponent();
            userResultService = UserResultService.getUserResultServiceInstance();
            resultService = ResultService.getResultServiceInstance();
            LoadForm();
        }

        public static FrmUserResults getFrmUserResultsInstance()
        {
            if (instance == null)
            {
                instance = new FrmUserResults();
            }
            instance.Select();
            return instance;
        }

        private void LoadForm()
        {
            List<UserResult> userResultList = new List<UserResult>();

            userResultList = userResultService.getUserResultListFilter("");

            DataTable dataTable = new DataTable();
            dataTable.Columns.AddRange(new DataColumn[8] {
                                new DataColumn("ID",typeof(int)),
                                new DataColumn("USUARIO",typeof(string)),
                                new DataColumn("E-MAIL",typeof(string)),
                                new DataColumn("EQUIPO 1",typeof(string)),
                                new DataColumn("RESULTADO 1",typeof(int)),
                                new DataColumn("EQUIPO 2",typeof(string)),
                                new DataColumn("RESULTADO 2",typeof(int)),
                                new DataColumn("PUNTOS",typeof(int))});

            foreach (UserResult userResult in userResultList)
            {

                dataTable.Rows.Add(userResult.getUser().getId(), userResult.getUser().getName(), userResult.getUser().getMail(),                                   
                                   userResult.getMatch().getTeam1().getName(), userResult.getVTeam1(),
                                   userResult.getMatch().getTeam2().getName(), userResult.getVTeam2(),
                                   userResult.getPoints());
            }

            dataGridView1.DataSource = dataTable;
            DgvFilterManager filterManager = new DgvFilterManager(dataGridView1);
        }
    }
}
